
import { WeElement, define } from 'omi'
import {get} from '../../../utils/util'
import api from "../../../api/api"
import './index.css'

define('page-my_order', class extends WeElement {
  config = {
    navigationBarTitleText: '我的订单'
  }

  data = {
    wd_order:"",
    logo:"",
    order_name:"",    
    order_list:[],  //订单列表
  }
  toreturn=(e)=>{
    console.log(e.currentTarget.dataset.sn);//订单号
    console.log(this.data.order_list);//订单
    wx.navigateTo({
      url:"../../return/index/index?order_sn="+e.currentTarget.dataset.sn+"&order_src="+ene.currtTarget.dataset.src+"&order_pri="+e.currentTarget.dataset.pri+"&order_name="+e.currentTarget.dataset.name,
    })
  }



  install() {
    this.data.wd_order = require('../images/wd_order.png'),
    this.data.logo = require('../images/logo.png'),
 
      //请求订单列表
      get(api.self_order).then((res)=>{
        console.log("res.data",res.data);
        this.data.order_list=res.data.filter((items)=>{
          if(items.order_state == 0){
            return false;
          }else{
            items.total_num = 0
            items.order_details.forEach( (details)=>{
              items.total_num += details.goods_num;
            })
            return true;
          }
        });      
        this.update();
      })
      
    this.update()
  }
  
  render() {
    return (
      <view class="container">
        <view class="content">
       {this.data.order_list.map((item,index)=>
          <view class="orders" key={item.order_id}>
            <image class="pic" src={item.order_details[0].goods_image}></image>
            <view class="order_content">
              <view class="order_name">{item.order_details[0].goods_name}</view>
              {/* <view class="order_desc">订单内容简介订单内容简介订单内容简介订单内容简介订单内容简介订单内容简介订单
内容简介订单内容简介订单内容简介</view> */}
              <view class="order_count">
                <view class="count">数量:{item.total_num}</view>
                <view class="price">金额:{item.order_amount }</view>
              </view>
              { item.order_state == 50 ?  
              <button class='change'>售后处理中</button>
              : 
              <button class="change" data-sn={item.order_sn} data-src={item.order_details[0].goods_image} data-pri={item.order_details[0].goods_pay_price} data-name={item.order_details[0].goods_name} bindtap={this.toreturn} >退换</button>
              }
            </view>
          </view>
          )}

        </view>
        <image class="logo" src={logo}></image>
      </view>
    )
  }
})